<template>
  <div class="risk">
    <div class="add" v-if="active == 1 || active == 2" @click="add()">新增</div>
    <van-search
      class="info_search input_text"
      v-model="value"
      @search="onSearch"
      @clear="clearSearch"
      placeholder="搜索"
    />

    <van-dropdown-menu>
      <van-dropdown-item
        v-model="value1"
        :options="option1"
        @change="handleTypeOneChange"
      :title="itemTitle "
      />
    </van-dropdown-menu>

    <!-- <van-tabs v-model="active">
      <van-tab title="现行制度"> -->
        <van-list
          style="margin: 10px"
          :finished="myFinished"
          v-model="myLoading"
          finished-text="没有更多了"
          @load="myOnLoad"
        >
          <van-cell
            style="margin-top: 10px"
            class="br-8"
            v-for="(item, index) in myList"
            :key="index"
          >
            <div class="warn_item">
              <div>
                <div class="warn_header">
                  <div>{{ item.HandBookName }}</div>
                </div>

                <van-row gutter="20" class="dep_sort">
                  <van-col span="24">
                    <img
                      src="@/assets/Images/AppIcon/icon_equ_type.png"
                      alt=""
                    />级别：{{ item.HandBookLevelName }}
                  </van-col>
                </van-row>
                <van-row gutter="20" class="dep_sort">
                  <van-col span="24">
                    <img
                      src="@/assets/Images/AppIcon/icon_equ_type.png"
                      alt=""
                    />所属部门：{{ item.OrgFullName }}
                  </van-col>
                </van-row>

                <van-row gutter="20" class="dep_sort">
                  <van-col span="24">
                    <img
                      src="@/assets/Images/AppIcon/icon_list_user.png"
                      alt=""
                    />录入人：{{ item.EditChnName }}
                  </van-col>
                </van-row>
                <van-row gutter="20" class="dep_sort">
                  <van-col span="24">
                    <img
                      src="@/assets/Images/AppIcon/icon_list_date.png"
                      alt=""
                    />录入时间：{{ item.EditDate }}
                  </van-col>
                </van-row>
              </div>
              <file-list-read-only
                :attachs="item.MainAttach"
                :labelName="'签名文件:'"
                v-if="item.MainAttach"
              ></file-list-read-only>

              <file-list-read-only
                :attachs="item.Attachs"
                :labelName="'附件:'"
                v-if="item.Attachs"
              ></file-list-read-only>

              <van-divider />
            </div>
          </van-cell>
        </van-list>
      <!-- </van-tab>
    </van-tabs> -->
  </div>
</template>

<script>
import { list } from "@/api/ZXTFGuidelineHandBook";
import { getDateTime } from "@/utils/getDate";
import FileListReadOnly from "../../../components/Attach/FileListReadOnly.vue";
export default {
  components: { FileListReadOnly },
  data() {
    return {
      value: "",
      myList: [],
      myFilter: {
        page: 0,
        dataType: "List",
      },
      value1: "",
option1: [
        { text: "不限", value: "" },
        { text: "公司级", value: "C" },
        { text: "部门级", value: "D" },
      ],
      seletTypeOne: [],
      loading: false,
      finished: false,
      myLoading: false,
      myFinished: false,
      itemTitle: '级别',
    };
  },
  created() {
    // this.getList();
    // this.getMyList();

    var conditions1 = [];
    if (this.value) {
      conditions1.push({
        Name: "Keywords",
        DisplayName: this.value,
        Value: this.value,
        Operator: "like",
        DataType: "String",
      });
    }

if (this.value1) {
        conditions1.push({
          Name: "HandBookLevel",
          Value: this.seletTypeOne[0].value,
          Operator: "=",
          DataType: "String",
          IsTemp:false
        });
      }


    this.myFilter.page = 0;
    this.myFilter.conditions = JSON.stringify(conditions1);
    this.getMyList();
  },
  methods: {

      handleTypeOneChange(value) {
      this.seletTypeOne = [];
      this.option1.map((item) => {
        if (item.value == value) {
          this.itemTitle = item.text
          this.value1 = item.value;
          this.seletTypeOne.push(item);
        }
      });
      this.onSearch();
    },
    onSearch() {
      var conditions1 = [];
      if (this.value) {
        conditions1.push({
          Name: "Keywords",
          DisplayName: this.value,
          Value: this.value,
          Operator: "like",
          DataType: "String",
        });
      }

      if (this.value1) {
        conditions1.push({
          Name: "HandBookLevel",
          Value: this.seletTypeOne[0].value,
          Operator: "=",
          DataType: "String",
          IsTemp:false
        });
      }

      this.myFilter.page = 0;
      this.myFilter.conditions = JSON.stringify(conditions1);
      this.getMyList();
    },
    clearSearch() {
      
      this.myFilter = {
        page: 0,
        dataType: "List",
      };

      this.value = "";
      this.getList();
    },
    getMyList() {
      this.myLoading = true;
      list(this.myFilter).then((res) => {
        this.myLoading = false;
        if (!res.data.HasNextPage) {
          this.myFinished = true;
        }
        res.data.Data.forEach((item) => {
          item.EditDate = getDateTime(item.EditDate);
        });

        // for (var i = 0; i < res.data.Data.length; i++) {
        //   if (res.data.Data[i].SignAttach) {
        //     res.data.Data[i].SignAttach = JSON.parse(
        //       res.data.Data[i].SignAttach.replace(/'/g, '"')
        //     );
        //   }
        // }

        this.myList = res.data.Data;
        this.myFilter.page = res.data.PageIndex;
      });
    },

    myOnLoad() {
      this.myLoading = true;
      ++this.myFilter.page;
      list(this.myFilter).then((res) => {
        this.myLoading = false;
        this.myFilter.page = res.data.PageIndex;
        this.myList = this.myList.concat(res.data.Data);
        if (!res.data.HasNextPage) {
          this.myFinished = true;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.risk {
  background-color: #e8f1f8;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}
.all_dep {
  background-color: #ffffff;
}

.warn_item {
  /*margin-bottom: 10px;*/
  // padding: 10px 0 10px 10px;
  border-radius: 5px;
  position: relative;
}
.warn_header {
  display: flex;
  justify-content: space-between;
  position: relative;
  margin-bottom: 10px;
  .warn_tag {
    position: absolute;
    right: 0;
    top: 0;
    border-radius: 26.64rem 0 0 26.64rem;
  }
}
.dep_sort {
  // display: flex;
  // flex-wrap: wrap;
  // margin-bottom: 5px;
  img {
    height: 15px;
    width: 15px;
    margin-right: 5px;
  }
}
.dep_btm {
  display: flex;
  justify-content: flex-end;
  width: 30%;
  float: right;
  .btm_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}
</style>
